﻿using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace WCFRestfulService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together.
    [ServiceContract(Namespace = "")]
    public interface IService
    {
        /*
         *WebGet属性使用GET动词暴露操作。通过在一个浏览器地址栏中输入服务URI可以直接地访问终结点
         * WebInvoke属性被用于那些修改数据的添加或者删除客户信息的操作。
        */


        // WebGet attribute is used to make GET request in WCF REST service
        [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetAllUsers")]
        ReturnJsonInfo<List<UserInfo>> GetAllUsers();

        // WebGet attribute is used to make GET request in WCF REST service
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetUser/{id}")]
        ReturnJsonInfo<UserInfo> GetUser(string id);

        [OperationContract]
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "AddUser")]
        ReturnJsonInfo<int> AddUser(UserInfo user);

        // WebInvoke attribute is used to make POST, DELETE and PUT request in WCF REST service
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "UpdateUser")]
        ReturnJsonInfo<UserInfo> UpdateUser(UserInfo user);

        // WebInvoke attribute is used to make POST, DELETE and PUT request in WCF REST service
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "DeleteUser/{id}")]
        ReturnJsonInfo<int> DeleteUser(string id);
    }
}
